home *** CD-ROM | disk | FTP | other *** search
- Path: erich.triumf.ca!bennett
- From: bennett@erich.triumf.ca (P.Bennett)
- Newsgroups: comp.lang.c
- Subject: Re: command line argument help
- Date: 27 Jan 1996 15:20 PST
- Organization: TRIUMF: Tri-University Meson Facility
- Distribution: world
- Message-ID: <27JAN199615205492@erich.triumf.ca>
- References: <4edfth$ok@muss.CIS.McMaster.CA>
- NNTP-Posting-Host: erich.triumf.ca
- News-Software: VAX/VMS VNEWS 1.50
-
- In article <4edfth$ok@muss.CIS.McMaster.CA>, shadowfax writes...
- >to all the c gods out there:
- >
- >i am not having too much success with command line arguments. i am
- >trying to make a simple sumation executable for dos. i am using borland
- >c++ v3.1. what i want as the end result is the user just types:
- >
- >c:\> sum 6 3
- >
- >and the executable would output an answer of 9. the following is my program:
-
- >#include <stdio.h>
- >#include <stdlib.h>
- >
- >int main(char *argv[])
-
- This should be:
-
- int main(int argc, char *argv[]);
-
- >{
- > int iSum = 0;
-
- You should check the value of argc here, to ensure that the user has entered
- enough values, and that you won't try to read more than he has entered.
-
- > iSum = atoi(argv[1]) + atoi(argv[2]);
- > printf("\nthe answer is %d", iSum);
-
- > return(0);
- >}
- >
- >when i compile and run, it always outputs an anser of 0. can anyone tell
- >me what's wrong?
-
- Since the first argument of main() is a count of the number of arguments, and
- your program treated it as a char * to the arguments, anything could happen!
-
- Peter Bennett VE7CEI | Vessels shall be deemed to be in sight
- Internet: bennett@triumf.ca | of one another only when one can be
- Packet: ve7cei@ve7kit.#vanc.bc.ca | observed visually from the other
- TRIUMF, Vancouver, B.C., Canada | ColRegs 3(k)
- GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
-
-
-
-
-
-
-
-